<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CashDraw extends Model
{
    use HasFactory;

    const STATUS_UNPAID = 'unpaid';
    const STATUS_PAID = 'paid';
    const STATUS_FAILED = 'failed';

    public static $statusMap = [
        self::STATUS_PAID => '已付款',
        self::STATUS_UNPAID => '未打款',
        self::STATUS_FAILED => '失败'
    ];

    protected $fillable = [
        'user_id', 'merchant_id', 'cash_info_id', 'status', 'cash_type', 'realname', 'account', 'amount', 'remark', 'paid_at', 'trade_no'
    ];

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        self::creating(function (CashDraw $model) {
            $model->status = CashDraw::STATUS_UNPAID;
        });
    }
}
